package geppetto.decoder;

import java.util.Arrays;
import java.util.LinkedList;

public class TranslationHypothesis {
	protected boolean[] usedSourceWords;
	protected int translatedWordIndex;
	protected LinkedList<TranslationOption> usedOptions = new LinkedList<TranslationOption>();

	public TranslationHypothesis(boolean[] usedSourceWords,
			int translatedWordIndex, LinkedList<TranslationOption> usedOptions) {
		super();
		this.usedSourceWords = usedSourceWords;
		this.translatedWordIndex = translatedWordIndex;
		this.usedOptions = usedOptions;
	}

	public boolean[] getUsedSourceWords() {
		return usedSourceWords;
	}

	public void setUsedSourceWords(boolean[] usedSourceWords) {
		this.usedSourceWords = usedSourceWords;
	}

	public int getTranslatedWordIndex() {
		return translatedWordIndex;
	}

	public void setTranslatedWordIndex(int translatedWordIndex) {
		this.translatedWordIndex = translatedWordIndex;
	}

	public TranslationHypothesis addOption(TranslationOption option) {
		boolean[] usedSourceWord = new boolean[this.getUsedSourceWords().length];
		LinkedList<TranslationOption> options = new LinkedList<TranslationOption>();
		System.arraycopy(this.getUsedSourceWords(), 0, usedSourceWord, 0,
				usedSourceWord.length);
		for (int i = option.sourceS; i <= option.sourceE; i++) {
			usedSourceWord[i] = true;
		}
		int lastTargetIndex = this.getTranslatedWordIndex()
				+ option.getTargetE() - option.getTargetS() + 1;
		for (TranslationOption o : usedOptions) {
			options.addLast(o);
		}
		options.addLast(option);
		TranslationHypothesis newHyp = new TranslationHypothesis(
				usedSourceWord, lastTargetIndex, options);
		return newHyp;
	}

	public static TranslationHypothesis generateNullHypothesis(int sourceSize) {
		boolean[] usedSourceWords = new boolean[sourceSize];
		Arrays.fill(usedSourceWords, Boolean.FALSE);
		return new TranslationHypothesis(usedSourceWords, -1,
				new LinkedList<TranslationOption>());
	}

	public LinkedList<TranslationOption> getUsedOptions() {
		return usedOptions;
	}
}
